package rensoft.portfolio.client.lib.view.richtexteditor;

import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.RichTextArea;

import rensoft.gwt.client.view.View;

import rensoft.portfolio.client.lib.view.ClosableDialogCaption;




public class RichTextEditor extends View<FlowPanel> {
  private final HasHTML hashtml;
  private final RichTextArea editor = new RichTextArea();
  private final RichTextToolbar tootlbar = new RichTextToolbar(editor);
  private final ClosableDialogCaption caption = new ClosableDialogCaption();
  private final DialogBox dialog = new DialogBox(caption) {
    @Override
    public void hide(boolean autoClosed) {
      hashtml.setHTML(editor.getHTML());
      super.hide(autoClosed);
    }
  };

  public RichTextEditor(HasHTML hashtml) {
    this.hashtml = hashtml;
    initWidget(new FlowPanel());
    widget().add(tootlbar);
    widget().add(editor);
    tootlbar.setWidth("100%");
    editor.setSize("640px", "480px");
    editor.setHTML(hashtml.getHTML());
    caption.setDialog(dialog);
    dialog.setWidget(this);
    dialog.center();
  }
}
